package com.yidu.hbatsft.service.impl;

import com.yidu.hbatsft.dao.AtsBaseSportItemMapper;
import com.yidu.hbatsft.domain.AtsBaseSportItem;
import com.yidu.hbatsft.service.AtsBaseSportItemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;

/**
 * @author hp
 */
@Service
public class AtsBaseSportItemServiceImpl implements AtsBaseSportItemService {

    @Resource
    AtsBaseSportItemMapper atsBaseSportItemMapper;

    @Override
    public List<AtsBaseSportItem> selectAll() {
        return atsBaseSportItemMapper.selectAll();
    }

    @Override
    public List<AtsBaseSportItem> findId(Integer integer) {
        return atsBaseSportItemMapper.findId(integer);
    }

    @Override
    public int insert(String ids, int id) {
        List<AtsBaseSportItem> list = atsBaseSportItemMapper.selectSportId(id);
        for (Iterator iterator = list.iterator(); iterator.hasNext();) {
            AtsBaseSportItem atsBaseSportItem = (AtsBaseSportItem) iterator.next();
            System.out.println("得到的id"+atsBaseSportItem.getSiId());
            atsBaseSportItemMapper.deleteByPrimaryKey(atsBaseSportItem.getSiId());
        }
        String temp[] = ids.split(",");
        for (int i = 0; i < temp.length; i++) {
            String pid = temp[i];
            System.out.println("shadoap:"+pid);
            AtsBaseSportItem atsBaseSportItem = new AtsBaseSportItem();
            atsBaseSportItem.setItemId(id);
            atsBaseSportItem.setSportId(Integer.valueOf(pid));
            atsBaseSportItem.setIsva(1);
            System.out.println("增加："+i+"次");
            atsBaseSportItemMapper.insert(atsBaseSportItem);
        }
        return 0;
    }

    @Override
    public List<AtsBaseSportItem> findPId(Integer integer) {
        return atsBaseSportItemMapper.findPId(integer);
    }

    @Override
    public int xhzj(String ids, Integer pid) {
        List<AtsBaseSportItem> list = atsBaseSportItemMapper.findPId(pid);
        for (Iterator iterator = list.iterator(); iterator.hasNext();) {
            AtsBaseSportItem atsBaseSportItem = (AtsBaseSportItem) iterator.next();
            atsBaseSportItemMapper.deleteByPrimaryKey(atsBaseSportItem.getSiId());
        }
        String temp[] = ids.split(",");
        for (int i = 0; i < temp.length; i++) {
            String pId = temp[i];
            System.out.println("shadoap:"+pId);
            AtsBaseSportItem atsBaseSportItem = new AtsBaseSportItem();
            atsBaseSportItem.setIsva(1);
            atsBaseSportItem.setItemId(Integer.valueOf(pId));
            atsBaseSportItem.setSportId(pid);
            atsBaseSportItemMapper.insert(atsBaseSportItem);
        }
        return 0;
    }

    /**
     * 根据体育项目查询所有指标
     * @param sportId
     * @return
     */
    @Override
    public List<AtsBaseSportItem> selectId(Integer sportId,Integer isva) {
        return atsBaseSportItemMapper.selectId(sportId,isva);
    }
}
